function t(t, e, o) {
    return e in t ? Object.defineProperty(t, e, {
        value: o,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = o, t;
}

var e, o, a = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
        return typeof t;
    } : function (t) {
        return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
    },
    i = require("../../../utils/function.js"),
    n = getApp(),
    r = require("../../../api.js");

Page({
    data: (e = {
            travel_type: '',
            waitStatus: 0,
            wait_time: "00:00:00",
            reSetMarker: !1,
            prices: "",
            km: "",
            is_online_price: "",
            dingshi: "",
            timer: "",
            latitude: "",
            longitude: "",
            markers: [{
                iconPath: "../../../images/driver/icon-30.png",
                id: 0,
                longitude: 108.94,
                latitude: 34.28,
                width: 15,
                height: 27
            }],
            polyline: [{
                points: [{
                    longitude: wx.getStorageSync("startAddress").longitude,
                    latitude: wx.getStorageSync("startAddress").latitude
                }, {
                    longitude: 108.94,
                    latitude: wx.getStorageSync("startAddress").latitude
                }],
                color: "#0299de",
                width: 9,
                dottedLine: !1,
                arrowLine: !0
            }],
            controls: [{
                id: 0,
                iconPath: "../../../images/user/icon-30.png",
                position: {
                    left: 10,
                    top: 10,
                    width: 50,
                    height: 50
                },
                clickable: !0
            }]
        }, t(e, "longitude", null), t(e, "latitude", null), t(e, "order_no", ""), t(e, "clears", 0),
        e),
    waitEvent: function (t) {
        var e = t.currentTarget.dataset.type,
            a = this.data.order_no,
            i = this;
        n.request({
            url: r.driver.resetOrder,
            method: "post",
            data: {
                type: e,
                order_no: a
            },
            success: function (t) {
                if (wx.showToast({
                        title: t.msg,
                        icon: "none"
                    }), 0 == t.code) return !1;
                0 == e ? (n.musicPlay("https://driving.4hl.cn/WeChat/resource/video/wait_status.mp3"), //等待状态
                    i.setData({
                        waitStatus: 1
                    }), i.getWaitTime()) : (n.musicPlay("http://dishichuxing.cn/fixedmp3/nindedingdanyikaishiqinganquanjiashi.mp3"), //您的代驾已开始 
                    i.setData({
                        waitStatus: 0
                    }), clearInterval(o), wx.removeStorage({
                        key: "wait_time"
                    }));
            }
        });
    },
    changeIcon: function () {
        var t = this,
            e = this.data.controls;
        wx.getSystemInfo({
            success: function (o) {
                var a = o.windowWidth / 750 * 130,
                    i = o.windowHeight - a;
                e[0] = {
                    id: 0,
                    iconPath: "../../../images/user/icon-30.png",
                    position: {
                        top: i - 56,
                        left: 10,
                        width: 50,
                        height: 50
                    },
                    clickable: !0
                }, t.setData({
                    winPath: {
                        w: o.windowWidth,
                        h: o.windowHeight
                    },
                    map_height: i,
                    controls: e
                });
            }
        });
    },
    getPolyline: function () {
        var t = this;
        i.getPolyline(function (e) {
            var o = t.data.polyline;
            o[0].points = e, t.setData({
                polyline: o
            });
        });
    },
    get_lat_lng: function (t) {
        var e = this;
        wx.getLocation({
            type: "gcj02",
            success: function (o) {
                console.log(o, "22222222222222");
                var a = o.latitude,
                    i = o.longitude,
                    n = a + "," + i;
                wx.request({
                    url: "https://apis.map.qq.com/ws/geocoder/v1/?l&get_poi=1",
                    data: {
                        key: wx.getStorageSync("MAP_KEY"),
                        location: n
                    },
                    method: "GET",
                    success: function (o) {
                        console.log(o), e.setData({
                            now_location: o.data.result
                        }), t({
                            now_location: o.data.result.address,
                            latitude: a,
                            longitude: i
                        });
                    }
                });
            }
        });
    },
    intoPageHandler: function (t) {
        var e = this,
            a = this.data.is_online_price;
        if (this.data.travel_type == 1) {
            if (clearInterval(o), wx.getStorageSync("OPEN_UPLOAD_PIC") && 0 == this.data.formData.length) return wx.navigateTo({
                url: "/pages/driver/evidence/index?type=endEvidence"
            }), !1;
        }

        wx.showModal({
            title: "提示",
            content: "确定结束进程？",
            success: function (o) {
                if (o.confirm) {
                    if (wx.removeStorageSync("wait_time"), n.musicPlay("http://dishichuxing.cn/fixedmp3/nindedingdanyijieshu.mp3"), //您的代驾以结束 又可以接新单了
                        wx.removeStorageSync("endEvidence"), wx.stopLocationUpdate({
                            success: function (t) {
                                wx.offLocationChange(function (t) {
                                    console.log("结束成功");
                                });
                            },
                            fail: function (t) {
                                console.log("结束失败", t);
                            }
                        }), 1 == a) {
                        clearInterval(e.data.dingshi);
                        var i = [{
                            latitude: "",
                            longitude: ""
                        }];
                        n.driver_position = i;
                    }
                    console.log("结束行程结果", e.data.order_no);
                    var s = t.detail.formId;
                    e.get_lat_lng(function (o) {
                        console.log(o.now_location);
                        var a = o.now_location,
                            i = o.latitude,
                            d = o.longitude;
                        n.request({
                            url: r.order.orderend,
                            method: "post",
                            data: {
                                formid: s,
                                end_point: a,
                                order_no: t.currentTarget.dataset.order_no,
                                longitude: d,
                                latitude: i,
                                after_pics: e.data.formData || []
                            },
                            success: function (e) {
                                1 == e.code ? (1 == e.data.is_abnormal && n.gateway(t.currentTarget.dataset.order_no, 3),
                                    wx.redirectTo({
                                        url: t.currentTarget.dataset.skip
                                    })) : wx.showToast({
                                    title: e.msg
                                });
                            }
                        });
                    }), n.endReportHeart();
                }
            }
        });
    },
    onLoad: function (t) {
        var e = this;
        clearInterval(o), wx.getStorageSync("wait_time") && (this.setData({
            waitStatus: 1
        }), e.getWaitTime(wx.getStorageSync("wait_time"))), n.request({
            url: r.order.isOnlinePrice,
            method: "post",
            data: {},
            success: function (t) {
                console.log("是否开始实施计费", t), 1 == t.code && (1 == t.data.is_online_price && e.startReportHearts(),
                    e.setData({
                        is_online_price: t.data.is_online_price
                    }));
            }
        }), console.log("开始行程", t), e.setData({
            order_no: t.order_no
        }), t.uid && n.shareCouponsMessage(t.uid), this.changeIcon();
    },
    getWaitTime: function (t) {
        var e = this;
        t = t || 0, o = setInterval(function () {
            t++, wx.setStorageSync("wait_time", t), console.log(e.formatSeconds(t)), e.setData({
                wait_time: e.formatSeconds(t)
            });
        }, 1e3);
    },
    onHide: function () {},
    formatSeconds: function (t) {
        var e = parseInt(t),
            o = 0,
            a = 0;
        e > 59 && (o = parseInt(e / 60), e = parseInt(e % 60), o > 59 && (a = parseInt(o / 60),
            o = parseInt(o % 60)));
        var i = "" + parseInt(e);
        return i < 10 && (i = "0" + i), i = 10 > o > 0 ? "0" + parseInt(o) + ":" + i : parseInt(o) + ":" + i,
            i = 10 > a > 0 ? "0" + parseInt(a) + ":" + i : parseInt(a) + ":" + i;
    },
    timeTask: function () {
        var t = this;
        n.request({
            url: r.real_time.geting,
            method: "post",
            data: {
                order_no: t.data.order_no
            },
            success: function (t) {
                console.log("经纬度", t.data);
            }
        });
    },
    onReady: function () {},
    onUnload: function () {
        var t = this;
        console.log("隐藏页面，Ia---/*-*-/--*/-*/-*"), clearInterval(t.data.dingshi);
    },
    startReportHearts: function () {
        var t = this;
        console.log("执行-------");
        var e = this.data.polyline,
            o = setInterval(function () {
                if (console.log("路线规划"), t.reSetMarker && n.driver_position[n.driver_position.length - 1]) {
                    var o = t.data.markers;
                    console.log(o);
                    var i = [];
                    for (var r in o) {
                        r = Number(r), console.log(void 0 === r ? "undefined" : a(r), r);
                        var s = {
                            id: r,
                            latitude: 0 == r ? n.driver_position[n.driver_position.length - 1].latitude : o[r].latitude,
                            longitude: 0 == r ? n.driver_position[n.driver_position.length - 1].longitude : o[r].longitude,
                            width: 40,
                            height: 40,
                            iconPath: o[r].iconPath
                        };
                        i.push(s);
                    }
                    t.setData({
                        markers: i
                    });
                }
                e[0].points = n.driver_position, console.log(e), t.setData({
                    longitude: n.longitudes,
                    latitude: n.latitudes,
                    prices: n.actual_km_price,
                    km: n.actual_km,
                    polyline: e
                });
            }, 2e3);
        this.setData({
            dingshi: o
        });
    },
    onShow: function () {
        this.data.formData = wx.getStorageSync("endEvidence") || [];
        var t = this;
        n.request({
            url: r.order.isOnlinePrice,
            method: "post",
            data: {},
            success: function (e) {
                if (console.log("是否开始实施计费", e), 1 == e.code)
                    if (1 == e.data.is_online_price) {
                        var o = t.data.order_no;
                        n.startReportHeart(o), console.log("开始行程结果", t.data.order_no), n.request({
                            url: r.order.getfind,
                            method: "post",
                            data: {
                                order_no: t.data.order_no
                            },
                            success: function (e) {
                                1 == e.code ? (t.reSetMarker = !0, t.setData({
                                    order: e.data,
                                    markers: e.data.slocaltion,
                                    driver: wx.getStorageSync("driver"),
                                    longitude: e.data.elocaltion.lng,
                                    latitude: e.data.elocaltion.lat,
                                    elocation: e.data.elocaltion,
                                    slocation: e.data.slocation.location,
                                    target_adds: e.data.target_adds,
                                    travel_type:e.data.travel_type

                                }), wx.setStorageSync("startAddress", e.data.slocation), wx.setStorageSync("endAddress", e.data.elocation)) : (wx.showToast({
                                    title: e.msg
                                }), wx.redirectTo({
                                    url: ""
                                }), wx.redirectTo({
                                    url: "../orderedStatus/orderedStatus?order_no=" + t.data.order_no
                                }));
                            }
                        });
                    } else console.log("开始行程结果", t.data.order_no), n.request({
                        url: r.order.getfind,
                        method: "post",
                        data: {
                            order_no: t.data.order_no
                        },
                        success: function (e) {
                            1 == e.code ? (t.setData({
                                    order: e.data,
                                    markers: e.data.slocaltion,
                                    driver: wx.getStorageSync("driver"),
                                    longitude: e.data.elocaltion.lng,
                                    latitude: e.data.elocaltion.lat,
                                    elocation: e.data.elocaltion,
                                    slocation: e.data.slocation.location,
                                    travel_type:e.data.travel_type
                                }), wx.setStorageSync("startAddress", e.data.slocation), wx.setStorageSync("endAddress", e.data.elocation),
                                t.getPolyline()) : (wx.showToast({
                                title: e.msg
                            }), wx.redirectTo({
                                url: ""
                            }), wx.redirectTo({
                                url: "../orderedStatus/orderedStatus?order_no=" + t.data.order_no
                            }));
                        }
                    });
            }
        }), this.changeMapHeight();
    },
    changeMapHeight: function () {
        var t = this;
        wx.getSystemInfo({
            success: function (e) {
                console.log(e, "22222222222222222222");
                var o = e.windowWidth / 750 * 110,
                    a = e.windowHeight - o,
                    i = [{
                        id: 1,
                        iconPath: "../../../images/driver/icon-50.png",
                        position: {
                            left: 10,
                            top: a - 150,
                            width: 50,
                            height: 50
                        },
                        clickable: !0
                    }, {
                        id: 2,
                        iconPath: "../../../images/driver/end.png",
                        position: {
                            left: 10,
                            top: a - 206,
                            width: 50,
                            height: 50
                        },
                        clickable: !0
                    }];
                t.setData({
                    winPath: {
                        w: e.windowWidth,
                        h: e.windowHeight
                    },
                    map_height: a,
                    controls: i
                });
            }
        });
    },
    controltap: function (t) {
        if (1 != t.controlId)
            if (2 != t.controlId) {
                var e = this;
                console.log("map controltap", t.controlId);
                wx.getLocation({
                    type: "gcj02",
                    success: function (t) {
                        console.log(t), e.setData({
                            longitude: t.longitude,
                            latitude: t.latitude
                        });
                    }
                });
            } else this.startHandler();
        else this.getAddress();
    },
    getAddress: function () {
        var t = this;
        wx.getLocation({
            success: function (e) {
                t.setData({
                    latitude: e.latitude,
                    longitude: e.longitude
                });
            }
        });
    },
    startHandler: function () {
        var t = this.data.elocation,
            e = this.data.target_adds;
        console.log(t), t.lat && t.lng && wx.openLocation({
            name: e,
            latitude: t.lat,
            longitude: t.lng
        });
    },
    onShareAppMessage: function () {
        var t = n.shareAppMessage().title,
            e = n.shareAppMessage().imageUrl,
            o = n.shareAppMessage().desc,
            a = n.shareAppMessage().path;
        return console.log(n.shareAppMessage()), {
            title: t,
            imageUrl: e,
            desc: o,
            path: a
        };
    }
});